﻿using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Linq;
using System.Web;
using Nop.Data;
using System.Data.Services.Common;
using System.Data.Objects;
using System.Data.Entity.Infrastructure;
using Nop.Core.Infrastructure;

namespace Nop.Plugin.Remote.Vishnu
{
    public class VishnuDataService : DataService<ObjectContext>
    {
        // Cette méthode n'est appelée qu'une seule fois pour initialiser les stratégies au niveau des services.
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("Orders", EntitySetRights.AllRead);
            config.SetEntitySetAccessRule("OrderProductVariants", EntitySetRights.AllRead);

            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }


        protected override ObjectContext CreateDataSource()
        {
            NopObjectContext nopObjectContext = (NopObjectContext)EngineContext.Current.Resolve<IDbContext>();
            ObjectContext context = ((IObjectContextAdapter)nopObjectContext).ObjectContext;

            context.ContextOptions.ProxyCreationEnabled = false;

            return context;
        }

    }
}
